<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<style type="text/css">
			form.mui-input-group {
				margin: 20px 0;
			}
			
			form.mui-input-group label {
				width: 35%;
				font-size: 14px;
			}
			
			form.mui-input-group input {
				width: 65%;
				font-size: 14px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-back mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改密码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>原密码</label>
					<input type="text" id="old-pwd" class="mui-input-clear mui-input" placeholder="请输入">
				</div>
				<div class="mui-input-row">
					<label>新密码</label>
					<input type="text" id="new-pwd" class="mui-input-clear mui-input" placeholder="至少 6 个字符">
				</div>
				<div class="mui-input-row">
					<label>确认密码</label>
					<input type="text" id="new-pwd-confirm" class="mui-input-clear mui-input" placeholder="请重新输入">
				</div>
			</form>
			<button class="mui-btn btn-block btn-main">确认</button>
		</div>
		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/user.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var oldPwd = document.getElementById("old-pwd");
			var newPwd = document.getElementById("new-pwd");
			var newPwdConf = document.getElementById("new-pwd-confirm");
			
			mui.plusReady(function() {
				mui('.mui-content').on('tap', 'button', function() {
					if(oldPwd.value.length >= 6 && newPwd.value.length >= 6 && newPwdConf.value.length >= 6) {
						if(newPwd.value == newPwdConf.value) {
							var url = baseURL + '/user/changePWD/' + oldPwd.value + '/' + newPwd.value + '.json';
							console.log(url);
							Common.ajax({
								url : url
							}, function(data) {
								console.log(JSON.stringify(data));
								if(data.code == 1) {
									mui.toast('修改密码成功，请使用新密码重新登录');
									mui.fire(plus.webview.currentWebview().opener(), 'back');
									mui.back();
								} else if(data.code == 0){
									mui.toast('原密码错误，请重新输入');
								} else {
									mui.toast('密码修改失败，' + data.msg);
								}
							}, function(xhr) {
								mui.toast('网络异常，请稍后再试');
								console.error('failed - ' + xhr.status + ' : ' + xhr.statusText);
							})
						} else {
							mui.toast('两次输入的密码不一致');
						}
					} else {
						mui.toast('您输入的信息不正确，请重新输入');
					}
				})
			})
		</script>
	</body>

</html>